package com.mijie.homi.dao.user;

import java.util.Date;
import java.util.List;
import java.util.HashMap;

import org.springframework.stereotype.Repository;

import com.mijie.core.IBatisDao;
import com.mijie.homi.common.domain.user.Friend;
import com.mijie.homi.common.util.HomiUtil;

@Repository
public class FriendDao extends IBatisDao {

	public boolean isFriend(int userId,int friendId){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("tableName", HomiUtil.getFriendTableName(userId));
		parameter.put("userId", userId);
		parameter.put("friendId", friendId);
		return this.selectInteger("isFriend", parameter)!=null;
	}
	
	public List<Friend> listFriend(int userId){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("tableName", HomiUtil.getFriendTableName(userId));
		parameter.put("userId", userId);
		return this.selectList("listFriend", parameter);
	}
	
	public List<Integer> listFriendId(int userId){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("tableName", HomiUtil.getFriendTableName(userId));
		parameter.put("userId", userId);
		return this.selectIntList("listFriendId", parameter);
	}
	
	public List<Integer> listBeFriendWithMeUser(int userId){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("tableName", HomiUtil.getFriendTableName(userId));
		parameter.put("userId", userId);
		return this.selectIntList("listBeFriendWithMeUser", parameter);
	}
	
	
	
	public int deleteFriend(int userId,int friendId){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("tableName", HomiUtil.getFriendTableName(userId));
		parameter.put("userId", userId);
		parameter.put("friendId", friendId);
		return this.delete("deleteFriend", parameter);
	}
	
	public int addFriend(int userId,int friendId){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("tableName", HomiUtil.getFriendTableName(userId));
		parameter.put("userId", userId);
		parameter.put("friendId", friendId);
		parameter.put("createAt", new Date());
		return this.delete("addFriend", parameter);
	}
	
}
